/**
 * 一只青蛙一次可以跳上1级台阶，也可以跳上2级……它也可以跳上n级。
 * 求该青蛙跳上一个n级的台阶总共有多少种跳法。
 * Created by MGL on 2017/2/24.
 */
public class Test01 {
    /*public int JumpFloor(int target) {
        int result = JumpFloor(target, 0, 0, 0);
        return result;
    }

    private int JumpFloor(int target, int jump, int sum, int count) {
        sum += jump;
        if (sum == target) {
            count++;
        } else if (sum < target) {
            count = JumpFloor(target, 1, sum, count);
            count = JumpFloor(target, 2, sum, count);
        }

        return count;
    }*/

    public int JumpFloor(int target) {
        if (target <= 0) return 0;
        if (target == 1) return 1;
        if (target == 2) return 2;
        int one = 1;
        int two = 2;
        int sum = 0;
        for (int i = 3; i <= target; i++) {
            sum = one + two;
            one = two;
            two = sum;
        }
        return sum;
    }

    public static void main(String[] args) {
        Test01 test01 = new Test01();
        int res = test01.JumpFloor(4);
        System.out.println(res);
    }

}
